package nl.altenpts.net;

import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
/**
 * Interface for channel handlers
 * 
 * @author fabian
 *
 */
public interface ChannelHandler {
	
	/**
	 * Returns the operations for channel in which the handler is interested in the readiness.
	 * The return value should be a bitwise or of one or more of the following values:
	 * <ul>
	 * 	<li> ACCEPT
	 *  <li> CONNECT
	 *  <li> READ
	 *  <li> WRITE
	 * </ul>
	 * This method is called by NetReactor to identify for which operations to check on
	 * channel. If 0 is returned then NetReactor drops channel and this ChannelHandler.
	 * @return For the handler interesting operations. 
	 */
	public int getRequestedOps(SelectableChannel channel);
	
	/**
	 * Notifies this ChannelHandler that channel is ready for the specified operations. 
	 */
	public void onReady(int operations, SelectableChannel channel);
	
	public static final int ACCEPT  = SelectionKey.OP_ACCEPT;
	public static final int CONNECT = SelectionKey.OP_CONNECT;
	public static final int READ    = SelectionKey.OP_READ;
	public static final int WRITE   = SelectionKey.OP_WRITE;

}
